<template>
  <div class="TabBar">
    <cube-tab-bar v-model="selectedLabelSlots" @click="handleClick" class="bd">
      <template v-for="(item, index) in tabs">
        <cube-tab :label="item.label" :key="index" class="tab">
          <i
            slot="icon"
            class="icon"
            :class="current === item.label ? item.selectedIcon : item.icon"
          ></i>
          <span class="text">{{ item.label }}</span>
        </cube-tab>
      </template>
    </cube-tab-bar>
  </div>
</template>
<script>
const tabList = {
  首页: "/",
  红包: "/mission/list",
  发现: "/discover",
  我的: "/user/profile"
};
export default {
  name: "TabBar",
  props: {
    current: String
  },
  data() {
    return {
      selectedLabelSlots: "首页",
      tabs: [
        {
          label: "首页",
          icon: "icon-home-gray",
          selectedIcon: "icon-home-color"
        },
        {
          label: "红包",
          icon: "icon-packet-gray",
          selectedIcon: "icon-packet-color"
        },
        {
          label: "发现",
          icon: "icon-discover-gray",
          selectedIcon: "icon-discover-color"
        },
        {
          label: "我的",
          icon: "icon-profile-gray",
          selectedIcon: "icon-profile-color"
        }
      ]
    };
  },
  mounted() {
    this.selectedLabelSlots = this.current;
  },
  methods: {
    handleClick(label) {
      const link = tabList[label];
      this.$router.replace(link);
    }
  }
};
</script>
<style lang="less" scoped>
.TabBar {
  height: 47px;
  .bd {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 47px;
    box-sizing: border-box;
    border-top: 1px solid #d6d6d6;
    background-color: #fff;
  }
  .tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    .icon {
      display: inline-block;
      width: 24px;
      height: 24px;
    }
    .text {
      padding-top: 3px;
      font-size: 9px;
      line-height: 9px;
      color: #9b9b9b;
    }
  }
}
</style>
